import Vue from 'vue';
import VueRouter from 'vue-router';
import Router from 'vue-router';
Vue.use(VueRouter);

const routes = [

  {
    path: '/',
    name: 'Index',
    component: () => import('../view/homeIndex/homeIndex.vue'),
    meta: {
      title: '首页'
    },
    children: [
      {
        path: '/demoItem',
        name: 'demoItem',
        meta: {
          title: '这个是demo1'
        },
        component: () => import('../view/demoItem/demoItem.vue'),
        children: [
          {
            path: '/demoItem/2',
            name: 'demo2',
            meta: {
              title: 'demo1的子内容'
            },
            component: () => import('../view/demoItem/demoItem2.vue'),
          }
        ],
      }, {
        path: '/demoItem2',
        name: 'demoItem2',
        component: () => import('../view/demoItem/demoItem3.vue'),
        meta: {
          title: '这个是demo2'
        }
        // children: []
      }
    ]
  }
  , {
    path: '*',
    name: '404',
    component: () => import('../view/404/noFound.vue'),
    meta: {
      title: '404'
    }
  }
];

//解决相同路由情况下跳转报错
const originalPush = Router.prototype.push;
Router.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err);
};


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
});

export default router;
